// pages/ruhui/ruhui.js
const app = getApp();
const $get_api = require('../../common/api').HTTP;
const wx_auth = require('../../common/wx_auth') //微信授权js
const util = require('../../utils/util')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    addImg:app.imgUrl + "ruhui/add.png?v="+app.timestamp,
    objData:{
    filling_date:"请选择：",
    name:"",phone:"",
    address:"",
    unit:"",
    license:"",//图片
    image:"",//图片
    id_card:"",
    birthday_date:"请选择：",
    education:"",
    duties:"",
    party:"",
    duties_title:"",
    nature:"",
    landline:"",
    wx:"",
    zipcode:"",
    biographical_notes:"",
    person_honor:"",
    organization:"",
    performance:"",
    unit_honor:"",
    introducer:"",
    unit_opinion:"",
    opinion_date:"请选择：",
    branch_sign_opinions:"",
    branch_sign_date:"请选择：",
    entrepreneurs_sign_opinions:"",
    join_date:"请选择："},
    qyxz_items: [
      { name: '国有', value: '国有', checked: 'true' },
      { name: '股份制', value: '股份制' },
      { name: '合资', value: '合资' },
      { name: '民营', value: '民营' },
      { name: '其他', value: '其他' },
    ],
    show1:true,
    show2:true,
    add_img_icon1:"",
    add_img_icon2:""
  },
 

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that=this;
    //console.log(that.data.objData.filling_date)
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let that=this;
    that.setData({
      'objData.nature':that.data.qyxz_items[0].value
    })
    console.log(that.data.objData.nature)
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  //姓名
  getNameValue(e){
    let that = this;
    that.data.objData.name = e.detail.value;
    that.setData({ 'objData.name' : e.detail.value})
    console.log(that.data.objData.name)
  },
  //手机号
  getPhoneValue(e){
    let that = this;
    that.data.objData.phone = e.detail.value;
    that.setData({ 'objData.phone' : e.detail.value})
    console.log(that.data.objData.phone)
  },
  //身份证
  getCardValue(e){
    let that = this;
    that.data.objData.id_card	 = e.detail.value;
    that.setData({ 'objData.id_card	' : e.detail.value})
    console.log(that.data.objData.id_card	)
  },
  //学历
  getEducationValue(e){
    let that = this;
    that.data.objData.education		 = e.detail.value;
    that.setData({ 'objData.education' : e.detail.value})
    console.log(that.data.objData.education		)
  },
  //职务
  getDutiesValue(e){
    let that = this;
    that.data.objData.duties = e.detail.value;
    that.setData({ 'objData.duties' : e.detail.value})
    console.log(that.data.objData.duties)
  },
  //党派
  getPartyValue(e){
    let that = this;
    that.data.objData.party = e.detail.value;
    that.setData({ 'objData.party' : e.detail.value})
    console.log(that.data.objData.party		)
  },
  //职称
  getDutisTitleValue(e){
    let that = this;
    that.data.objData.duties_title = e.detail.value;
    that.setData({ 'objData.duties_title' : e.detail.value})
    console.log(that.data.objData.duties_title)
  },
  //企业性质
  getNatureValue(e){
    let that = this;
    that.data.objData.nature = e.detail.value;
    that.setData({ 'objData.nature' : e.detail.value})
    console.log(that.data.objData.nature)
  },
  //办公电话
  getLandlineValue(e){
    let that = this;
    that.data.objData.landline = e.detail.value;
    that.setData({ 'objData.landline' : e.detail.value})
    console.log(that.data.objData.landline)
  },
  //微信号
  getWxValue(e){
    let that = this;
    that.data.objData.wx = e.detail.value;
    that.setData({ 'objData.wx' : e.detail.value})
    console.log(that.data.objData.wx)
  },
  getAddressValue(e){
    let that = this;
    that.data.objData.address = e.detail.value;
    that.setData({ 'objData.address' : e.detail.value})
    console.log(that.data.objData.address)
  },
  //邮编
  getZipcodeValue(e){
    let that = this;
    that.data.objData.zipcode = e.detail.value;
    that.setData({ 'objData.zipcode' : e.detail.value})
    console.log(that.data.objData.zipcode)
  },
  //个人简历
  getNotesValue(e){
    let that = this;
    that.data.objData.biographical_notes = e.detail.value;
    that.setData({ 'objData.biographical_notes' : e.detail.value})
    console.log(that.data.objData.biographical_notes)
  },
  //个人荣誉
  getHonorValue(e){
    let that = this;
    that.data.objData.person_honor = e.detail.value;
    that.setData({ 'objData.person_honor' : e.detail.value})
    console.log(that.data.objData.person_honor);
  },
  //组织情况
  getOrganizationValue(e){
    let that = this;
    that.data.objData.organization = e.detail.value;
    that.setData({ 'objData.organization' : e.detail.value})
    console.log(that.data.objData.organization);
  },
  //经营状况
  getPerformanceValue(e){
    let that = this;
    that.data.objData.performance = e.detail.value;
    that.setData({ 'objData.performance' : e.detail.value})
    console.log(that.data.objData.performance);
  },
  //单位
  getUnitValue(e){
    let that = this;
    that.data.objData.unit = e.detail.value;
    that.setData({ 'objData.unit' : e.detail.value})
    console.log(that.data.objData.unit);
  },
  //单位荣誉
  getUnitHonorValue(e){
    let that = this;
    that.data.objData.unit_honor = e.detail.value;
    that.setData({ 'objData.unit_honor' : e.detail.value})
    console.log(that.data.objData.unit_honor);
  },
  //介绍人
  getIntroducerValue(e){
    let that = this;
    that.data.objData.introducer = e.detail.value;
    that.setData({ 'objData.introducer' : e.detail.value})
    console.log(that.data.objData.introducer);
  },
  //单位意见
  getUnitOpinionValue(e){
    let that = this;
    that.data.objData.unit_opinion = e.detail.value;
    that.setData({'objData.unit_opinion' : e.detail.value})
    console.log(that.data.objData.unit_opinion);
  },
  //分会签署意见
  getBranchSignOpinionsValue(e){
    let that = this;
    that.data.objData.branch_sign_opinions = e.detail.value;
    that.setData({ 'objData.branch_sign_opinions' : e.detail.value})
    console.log(that.data.objData.branch_sign_opinions);
  },
  //女企业家签署意见
  getEntrepreneursSignOvpinionsValue(e){
    let that = this;
    that.data.objData.entrepreneurs_sign_opinions = e.detail.value;
    that.setData({ 'objData.entrepreneurs_sign_opinions' : e.detail.value})
    console.log(that.data.objData.entrepreneurs_sign_opinions);
  },
  //填表日期
  bindFillingDateChange(e){
    let that = this;
    that.data.objData.filling_date = e.detail.value;
    that.setData({ 'objData.filling_date' : e.detail.value})
    console.log(that.data.objData.filling_date)
  },
  //出生日期
  bindBirthdayChange(e){
    let that = this;
    that.data.objData.birthday_date = e.detail.value;
    that.setData({ 'objData.birthday_date' : e.detail.value})
    console.log(that.data.objData.birthday_date)
  },
  //意见时间
  bindOpinonDateChange(e){
    let that = this;
    that.data.objData.birthday_date = e.detail.value;
    that.setData({ 'objData.opinion_date' : e.detail.value})
    console.log(that.data.objData.opinion_date)
  },
  //分会签署时间
  bindBreanchSignDateChange(e){
    let that = this;
    that.data.objData.birthday_date = e.detail.value;
    that.setData({ 'objData.branch_sign_date' : e.detail.value})
    console.log(that.data.objData.branch_sign_date)
  },
  //入会时间
  bindJoinDateChange(e){
    let that = this;
    that.data.objData.join_date = e.detail.value;
    that.setData({ 'objData.join_date' : e.detail.value})
    console.log(that.data.objData.birthday_date)
  },
  radioChange:function(e)
  {
    let that=this;
    that.setData({
      'objData.nature': e.detail.value
    })
    console.log(that.data.objData.nature)
  },
  handchooseImg1:function(e)
  {
    let that=this;
    console.log("handchooseImg1")
    wx.chooseImage({
      count:1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success:function (res) {
        console.log(res)
        that.setData({
          add_img_icon1:res.tempFilePaths[0],
          show1:false
        })
       
        },
      fail:function(e) {
        // fail
        },
      complete:function(e) {
        console.log(e)
        that.ajaxUpload(e.tempFilePaths[0],1);
        }
    })
  },
  handchooseImg2:function(e)
  {
    let that=this;
    console.log("handchooseImg2")
    wx.chooseImage({
      count:1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success:function (res) {
        console.log(res)
        that.setData({
          add_img_icon2:res.tempFilePaths[0],
          show2:false
        })
       
        },
      fail:function(e) {
        // fail
        },
      complete:function(e) {
        console.log(e)
        that.ajaxUpload(e.tempFilePaths[0],2);
        }
    })
  },
  ajaxUpload:function(url,num){
    let that=this;
    console.log("ajaxUpload:"+url)
    wx.uploadFile({
      filePath: url,
      name: 'file',
      url: 'https://nqxxcx.whyimingkeji.com/api/ajaxUpload?token='+wx.getStorageSync('token'),//服务器端接收图片的路径
      success:function(res){
        console.log(res);//发送成功回调
        let data = res.data;
        data = (JSON.parse(data))
        if(data.code != 0){
          app.showError(data.message)
          return false;
       }
       data = data.data;
       console.log(data.url);//发送成功回调
       if(num==1)
       {
        that.setData({
          'objData.license':data.url
         })
       }
       else if(num==2)
       {
        that.setData({
          'objData.image':data.url
         })
       }
      },
      fail:function(res){
        console.log(res);//发送失败回调，可以在这里了解失败原因
      }
  })
  },
  bindJoiningMember:function(e){
    console.log("bindJoiningMember")
    let that = this;
    let objData=that.data.objData;
   $get_api.addJoiningMembership({ 
        name:objData.name,
        phone:objData.phone,
        address:objData.address,
        unit:objData.unit,
        license:objData.license,
        image:objData.image,
        id_card:objData.id_card,
        birthday_date:objData.birthday_date,
        education:objData.education,
        duties:objData.duties,
        party:objData.party,
        duties_title:objData.duties_title,
        nature:objData.nature,
        landline:objData.landline,
        wx:objData.wx,
        zipcode:objData.zipcode,
        biographical_notes:objData.biographical_notes,
        person_honor:objData.person_honor,
        organization:objData.organization,
        performance:objData.performance,
        unit_honor:objData.unit_honor,
        introducer:objData.introducer,
        unit_opinion:objData.unit_opinion,
        opinion_date:objData.opinion_date,
        branch_sign_opinions:objData.branch_sign_opinions,
        branch_sign_date:objData.branch_sign_date,
        entrepreneurs_sign_opinions:objData.entrepreneurs_sign_opinions,
        join_date:objData.join_date,
        filling_date:objData.filling_date,
    }).then(r => { 
        console.log(r);
       // app.showError(r.message)
       if(r.data.code == 0){
        wx.showToast({
          icon:"success",
          title: '申请成功',
        })
        setTimeout(() => {
           wx.switchTab({
              url: '../index/index',
            })
        }, 1500);
      }
      
    })
   }
})